home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / appkit.730 < prev    next >
Text File  |  1992-02-06  |  3KB  |  79 lines

  1. {\rtf0\ansi{\fonttbl\f1\fnil Times-Roman;\f2\fmodern Courier;\f0\fswiss Helvetica;}
  2. \paperw13040
  3. \paperh10140
  4. \margl120
  5. \margr80
  6. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f1\b0\i0\ul0\fs28 initialize NXImage initFromFile: bug workaround\
  7. \
  8.  
  9. \fi-440\li440 Q:  The documentation for the NXImage method 
  10. \b initFromFile:
  11. \b0  says:\
  12.  
  13. \fi0\li0 \
  14.  
  15. \pard\tx360\tx880\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fi20\li1360 After finishing the initialization, this method returns 
  16. \b self
  17. \b0 .  However, if the new instance can't be initialized, it is freed and 
  18. \b nil
  19. \b0  is returned.\
  20.  
  21. \pard\tx3120\tx3620\tx4120\li2620 \
  22.  
  23. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\li400 In my application, nil is never returned, even if I read in a bogus file.  Is this a bug?  Here is my code:\
  24. \
  25.  
  26. \f2\fs24\fi1040 id myNXImage = [NXImage alloc];\
  27. if ([myNXImage initFromFile: "dummyName.tiff"] == nil)\
  28. \{\
  29.     /* this is never getting called! */\
  30.     fprintf(stderr,"dummyName.tiff doesn't exist!\\n");\
  31. \}\
  32.  
  33. \f1\fs28\fi0\li0 \
  34.  
  35. \fi-440\li440 A:  This is not a bug although the documentation could be clearer.  The 
  36. \b initFromFile:
  37. \b0  method is lazy and will not catch 
  38. \i all
  39. \i0  the errors that might happen when loading an image.  Your application should be prepared to check for errors later on down the line either through delegation or by checking the 
  40. \b composite:
  41. \b0  or 
  42. \b lockFocus
  43. \b0  return values.  If you wish, you can force the image to be rendered immediately:\
  44.  
  45. \fi0\li0 \
  46.  
  47. \f2\fs24\fi1040\li400 id myNXImage = [[NXImage alloc] initFromFile: filename];\
  48. if ([myNXImage lockFocus])\
  49.     [image unlockFocus];\
  50. else\
  51.     fprintf(stderr,"%s doesn't exist\\n", filename);\
  52.     \
  53. \
  54.  
  55. \f1\fs28\fi0 Although this behavior might seem confusing it allows for more optimal performance:  the image isn't rendered into the cache until it is needed.  Rendering a large or complex file can be slow—particularly for a complex EPS file.\
  56. \
  57.  
  58. \b Note:
  59. \b0   Another good approach for determining whether an image can be successfully rendered is the NXImage delegate method 
  60. \b imageDidNotDraw:inRect:
  61. \b0 .  If you have assigned a delegate for the image and implemented this method, it gets called when compositing fails for whatever reason.  See the documentation on NXImage for more information about this method.  Also note that this method of delegation may be the only way to catch a drawing error for an image which is being "handed" to the AppKit—an icon on a button, for example.\
  62. \
  63. There is a known bug in Release 2 where 
  64. \b imageDidNotDraw:inRect:
  65. \b0  fails to be called when encountering an error from within the method 
  66. \b composite:toPoint:
  67. \b0 .  This bug can be avoided by using the NXImage method 
  68. \b composite:fromRect:toPoint:
  69. \b0 .\
  70.  
  71. \li0 \
  72. \
  73. QA730\
  74. \
  75. Not valid for 1.0\
  76. Valid for 2.0\
  77. \
  78.  
  79.